//
//  AvatarViewController.swift
//  AmountBody
//
//  Created by Qiu Jishuai on 2018/2/1.
//  Copyright © 2018年 RCMTM. All rights reserved.
//

import UIKit
import ReactiveCocoa

class AvatarViewController: BasePresentedViewController {

    let topLabel: UILabel = {
        let label = UILabel()
        label.textAlignment = .center
        label.font = UIFont.systemFont(ofSize: 10)
        label.textColor = UIColor.themeLightGrayColor
        label.text = "点击头像可更换"
        return label
    }()

    let avatarImageView: UIImageView = {
        let imageView = UIImageView()
        imageView.contentMode = .center
        imageView.image = #imageLiteral(resourceName: "头像")
        return imageView
    }()

    let nameLabel: UILabel = {
        let label = UILabel()
        label.numberOfLines = 2
        label.text = "XXB/n信息部"
        label.textAlignment = .center
        label.font = UIFont.systemFont(ofSize: 16)
        label.textColor = UIColor.themeDarkGrayColor
        return label
    }()

    let rankLabel: UILabel = {
        let label = UILabel()
        label.backgroundColor = UIColor.themeRedColor
        label.cornerRadius = 8
        label.textAlignment = .center
        label.text = "  超级权限  "
        label.font = UIFont.systemMediumFont(withSize: 8)
        label.textColor = UIColor.white
        return label
    }()

    lazy var passwordButton: UIButton = {
        let button = UIButton(type: .system)
        button.setTitleColor(UIColor.themeGrayColor, for: .normal)
        button.setTitle("修改密码", for: .normal)
        button.setImage(#imageLiteral(resourceName: "profile_btn_password").alwaysOriginal(), for: .normal)
        button.titleLabel?.font = UIFont.systemMediumFont(withSize: 14)
        return button
    }()

    lazy var logoutButton: UIButton = {
        let button = UIButton(type: .system)
        button.setTitle("安全退出", for: .normal)
        button.setImage(#imageLiteral(resourceName: "profile_btn_logout").alwaysOriginal(), for: .normal)
        button.setTitleColor(UIColor.themeGrayColor, for: .normal)
        button.titleLabel?.font = UIFont.systemMediumFont(withSize: 14)
        return button
    }()

    override func viewDidLoad() {
        super.viewDidLoad()

        setupViews()
    }
}

private extension AvatarViewController {
    func setupViews() {
        bgImageView.image = #imageLiteral(resourceName: "imaginary_rectangle")
        containerView.mas_remakeConstraints { (make) in
            make?.center.equalTo()(view)
            make?.width.height().equalTo()(view)?.multipliedBy()(0.5)
        }

        containerView.addSubview(bgImageView)
        containerView.addSubview(topLabel)
        containerView.addSubview(avatarImageView)
        containerView.addSubview(nameLabel)
        containerView.addSubview(rankLabel)
        containerView.addSubview(passwordButton)
        containerView.addSubview(logoutButton)

        let line = UIView()
        line.backgroundColor = UIColor.themeLightGrayColor
        containerView.addSubview(line)

        bgImageView.mas_remakeConstraints { (make) in
            make?.edges.equalTo()(containerView)?.insets()((-10).insets)
        }

        avatarImageView.mas_remakeConstraints { (make) in
            make?.centerX.equalTo()(containerView)
            make?.centerY.equalTo()(containerView.mas_top)?.offset()(80)
            make?.width.height().equalTo()(120)
        }

        topLabel.mas_makeConstraints { (make) in
            make?.centerX.equalTo()(avatarImageView)
            make?.bottom.equalTo()(avatarImageView.mas_top)?.offset()(-5)
        }

        nameLabel.mas_makeConstraints { (make) in
            make?.top.equalTo()(avatarImageView.mas_bottom)?.offset()(5)
            make?.centerX.equalTo()(avatarImageView)
        }

        rankLabel.mas_makeConstraints { (make) in
            make?.top.equalTo()(nameLabel.mas_bottom)?.offset()(3)
            make?.height.equalTo()(15)
            make?.centerX.equalTo()(avatarImageView)
        }

        passwordButton.mas_makeConstraints { (make) in
            make?.centerX.equalTo()(bgImageView)
            make?.bottom.equalTo()(bgImageView)?.offset()(-60)
            make?.size.equalTo()(CGSize(width: 92, height: 20))
        }

        line.mas_makeConstraints { (make) in
            make?.bottom.equalTo()(passwordButton.mas_top)?.offset()(-14)
            make?.centerX.equalTo()(passwordButton)
            make?.size.equalTo()(CGSize(width: 208, height: 1))
        }

        logoutButton.mas_makeConstraints { (make) in
            make?.bottom.equalTo()(line.mas_top)?.offset()(-14)
            make?.centerX.equalTo()(passwordButton)
            make?.size.equalTo()(CGSize(width: 92, height: 20))
        }
    }
}
